package com.day1;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;


import javax.servlet.http.*;
import java.io.IOException;
import java.util.Map;
import java.util.Set;

public class Success extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.service(req, resp);
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        String name = String.valueOf(req.getAttribute("name"));
        resp.getWriter().print(name+"登录成功");

        HttpSession session=req.getSession();
        Map<String,String> session1 = (Map<String, String>) session.getAttribute("session");
        Set<String> set1=session1.keySet();
        for (String ses:set1){
            System.out.println(ses+"="+session1.get(ses));
        }
        ServletContext servletContext = req.getServletContext();



        resp.getWriter().print("<a href='http://localhost:8080/hhh/fail'>退出</a>");
        Cookie[] cookies=req.getCookies();
        if (cookies!=null){
            for (Cookie ck:cookies){
                if (cookies.equals(ck.getName())){
                    ck.setMaxAge(0);
                    resp.addCookie(ck);
                    req.getRequestDispatcher("/fail");
                }
            }
        }

    }

    }

